/*
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2006-2007 Intel Corporation. All Rights Reserved.
//
*/
#include "umc_defs.h"
#if defined (UMC_ENABLE_DV_VIDEO_ENCODER)

#include "ippi.h"
#include "ipps.h"
#include "ippvc.h"
#include "umc_dv_enc_compressor_def.h"
#include "umc_dv_enc_segment_compressor.h"
#include "umc_dv_enc_block.h"

namespace UMC
{

void PreProcessBlock(BLOCK *lpBlock);

void SegmentCompressor::DoDCT()
{
    Ipp32s DCTBlockNum;
    for(DCTBlockNum=0; DCTBlockNum<30; DCTBlockNum++)
        PreProcessBlock(m_VSegment.m_pDCTBlocks + DCTBlockNum);
}

void PreProcessBlock(BLOCK *lpBlock)
{
    Ipp16s sTmp[64];
    Ipp32u countzero, countzero1;

    memcpy(sTmp, lpBlock->m_lpsData, 64 * sizeof(Ipp16s));
    ippiDCT8x8Fwd_16s_C1I(lpBlock->m_lpsData);
    ippsMul_16s_ISfs(QTableDouble0, lpBlock->m_lpsData, 64, 16);
    ippiDCT2x4x8Frw_16s_C1I(sTmp);
    ippsMul_16s_ISfs(QTableDouble1, sTmp, 64, 16);

    ippiCountZeros8x8_16s_C1(lpBlock->m_lpsData, &countzero);
    ippiCountZeros8x8_16s_C1(sTmp, &countzero1);
    if (countzero >= countzero1)
    {
        lpBlock->m_cM0 = 0;
    }
    else
    {
        lpBlock->m_cM0 = 1;
        memcpy(lpBlock->m_lpsData, sTmp, 64 * sizeof(Ipp16s));
    }
} // void PreProcessBlock(BLOCK *lpBlock)

}//namespace UMC

#endif //(UMC_ENABLE_DV_VIDEO_ENCODER)
